# -*- coding: utf-8 -*-
"""
Created on Thu Nov 11 08:32:52 2021

"""

import os, random, math, uuid
os.chdir("C:/Users/documents")

#path = os.getcwd()
#print(path)

import pandas as pd
from csv import writer


df0 = pd.read_csv("FLAGGAddressesAndInfo.csv")
df = df0.copy()


#set the radius it is in meters

R = 150

# convert radius from meters to degrees

r = R/111300

#list of longitudes

OriginalLongitudes = df['Longitude'].tolist()
x0 = OriginalLongitudes


#list of latitudes

OriginalLatitudes = df['Latitude'].tolist()
y0 = OriginalLatitudes


#Offset longitude

DeidentifiedLongitude = []

for i in range(len(x0)):
    u = random.random()
    v = random.random()
    w = r * math.sqrt(u)
    t = 2 * math.pi * v
    x = w * math.cos(t)
    y = w * math.sin(t)
    xPrime = x/math.cos(y0[i])
    NewX = x0[i] + xPrime
    DeidentifiedLongitude.append(NewX)
    
#offset latitude

DeidentifiedLatitude = []
for i in range(len(y0)):
    u = random.random()
    v = random.random()
    w = r * math.sqrt(u)
    t = 2 * math.pi * v
    x = w * math.cos(t)
    y = w * math.sin(t)
    NewY = y0[i] + y
    DeidentifiedLatitude.append(NewY)

#generate random IDs

IDs = []
for i in range(len(df['Name'])):
    ID = str(uuid.uuid4())
    IDs.append(ID)

#add lists to the dataframe

df['DeidentifiedLongitude'] = DeidentifiedLongitude
df['DeidentifiedLatitude'] = DeidentifiedLatitude
df['UniqueRandomLocationID'] = IDs

#write dataframe to a CSV

df.to_csv('FLAGGAddressesAndInfo2Output.csv')


#Quality checking
#print(len(df['UniqueRandomLocationID']))
